package com.runfast.waimai.service.impl;

import com.runfast.common.service.BaseService;
import com.runfast.paotui.dao.model.Order;
import com.runfast.waimai.dao.mapper.RunfastGoodsSellChildrenMapper;
import com.runfast.waimai.dao.mapper.RunfastGoodsSellRecordMapper;
import com.runfast.waimai.dao.model.RunfastGoodsSellChildren;
import com.runfast.waimai.dao.model.RunfastGoodsSellRecord;
import com.runfast.waimai.dao.model.RunfastGoodsSellRecordExample;
import com.runfast.waimai.service.RunfastGoodsSellRecordService;
import com.runfast.waimai.util.ComUtil;
import com.runfast.waimai.util.PageBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class RunfastGoodsSellRecordServiceImpl extends BaseService<RunfastGoodsSellRecord, Integer, RunfastGoodsSellRecordExample> implements RunfastGoodsSellRecordService {
   @Resource
    RunfastGoodsSellRecordMapper dao;
   @Resource
   RunfastGoodsSellChildrenMapper goodsSellRecordChildrenDao;

    @Override
    public Integer findBookTimecount(Integer shopperid, Date bookTime,Integer agentid) {
        return dao.findBookTimecount(shopperid,bookTime,agentid);
    }

    @Override
    public List<RunfastGoodsSellRecord> findByShopperAndSize(Integer shopperid) {
        return dao.findByShopperAndSize(shopperid);
    }

    @Override
    public Integer findByShopperIdAndStrutscount(Integer shopperid, Integer status) {
        return dao.findByShopperIdAndStrutscount( shopperid,  status);
    }

    @Override
    public List<RunfastGoodsSellRecord> findByShopperIdAndStruts(Integer shopperid, Integer status,Integer page,Integer pagesize) {
        return dao. findByShopperIdAndStruts( shopperid, status,page,pagesize);
    }

    @Override
    public List<RunfastGoodsSellRecord> findByShopperIdAndStrutsAndagree1(Integer shopperid, Integer status) {
        return dao.findByShopperIdAndStrutsAndagree1(shopperid, status);
    }

    @Override
    public List<RunfastGoodsSellRecord> findByShopperIdAndStrutsAndagree2(Integer shopperid, Integer status) {
        return dao.findByShopperIdAndStrutsAndagree2(shopperid, status);
    }

    @Override
    public RunfastGoodsSellRecord findByShopperIdAndId(Integer shopperid,Integer id) {
        return dao.findByShopperIdAndId(shopperid,id);
    }

    @Override
    public RunfastGoodsSellRecord findByShopperIdAndOrderCode(Integer shopperid, Integer id) {
        return dao.findByShopperIdAndOrderCode(shopperid,id);
    }

    @Override
    public RunfastGoodsSellRecord findByShopperIdAndOrderCode1(Integer shopperid, String orderCode) {
        return dao.findByShopperIdAndOrderCode1(shopperid, orderCode);
    }


    @Override
    public List<RunfastGoodsSellRecord> findById(Integer shopperid) {
        return dao.findById(shopperid);
    }

    @Override
    public RunfastGoodsSellRecord get(Integer id) {
        return dao.get(id);
    }

    @Override
    public RunfastGoodsSellRecord findByOrderCode(String ordercode) {
        return dao.findByOrderCode(ordercode);
    }

    @Override
    public PageBean<RunfastGoodsSellRecord> getPageBean4Driver(Integer pageSize, Integer page, Integer status, Integer shopperId, Integer agentid, Integer teamid) {
        RunfastGoodsSellRecord runfastGoodsSellRecord=new RunfastGoodsSellRecord();

       List<RunfastGoodsSellRecord>list= dao.findListPageBean(pageSize,page,status,shopperId,agentid,teamid);

        int count=dao.findCount(pageSize,page,status,shopperId,agentid,teamid);
        PageBean<RunfastGoodsSellRecord> pageBean=new PageBean<RunfastGoodsSellRecord>();
        pageBean.setAllRow(count);// 总记录数
        pageBean.setCurrentPage(page);// 当前页,每页面记录数为
        pageBean.setTotalPage(count/pageSize);// 总页数
        pageBean.setData(list);//设置当前页面的数据集合


        return pageBean;
//        List<RunfastGoodsSellRecordExample.Criterion> critList = new ArrayList<RunfastGoodsSellRecordExample.Criterion>();
//        List<Order> orderList = new ArrayList<Order>();
//        // -1：订单取消  0：客户下单，1：客户已付款 2：商品接单 3：骑手接单  4：商品打包 ，5：商品配送 6：商品送达，7:确认收货 ，8：订单完成
//        //订单类型：1新订单（商家已接单，但还没有配送员）2待取订单（商家已打包）3待送订单（配送员已取单，配送中...）
//        if(shopperId==null){
//            shopperId = -1;
//        }
//        if(agentid!=null){
//            critList.add(Restrictions.eq("agentId", agentid));
//        }
//        if(status==1){//
//
//            //critList.add(Restrictions.eq("status", 2));
//            critList.add(Restrictions.or(Restrictions.eq("status", 2), Restrictions.eq("status", 1)));
//            critList.add(Restrictions.isNull("shopperId"));
//        }else if(status==-10){
////			critList.add(Restrictions.eq("status", 2));
//            critList.add(Restrictions.or(Restrictions.eq("status", 2), Restrictions.eq("status", 1)));
//            critList.add(Restrictions.isNull("shopperId"));
//        }else if(status==2){
////			critList.add(Restrictions.or(Restrictions.eq("status", 3), Restrictions.eq("status", 2)));
////			critList.add(Restrictions.or(Restrictions.eq("status", 3), Restrictions.or(Restrictions.eq("status", 1), Restrictions.eq("status", 4))));
//            critList.add(Restrictions.le("status", 4));
//            critList.add(Restrictions.ge("status", 1));
//            critList.add(Restrictions.eq("shopperId", shopperId));
//        }else if(status==3){
//            critList.add(Restrictions.eq("status", 5));
//            critList.add(Restrictions.eq("shopperId", shopperId));
//        }else{
//            critList.add(Restrictions.eq("shopperId", shopperId));
//        }
//        if(teamid!=null){
//
//            if(teamid!=0){
//                critList.add(Restrictions.or(Restrictions.eq("teamid", teamid), Restrictions.eq("teamid", 0)));
//            }else{
//                critList.add(Restrictions.eq("teamid", teamid));
//            }
//        }else{
//            critList.add(Restrictions.eq("teamid", 0));
//        }
//        critList.add(Restrictions.ne("isDeliver", 1));
//        orderList.add(Order.asc("id"));
//        return super.getPageBean(pageSize, page, null, null, critList, orderList);
    }

    @Override
    public void update(RunfastGoodsSellRecord record) {
       dao.update(record);
    }

    @Override
    public List<RunfastGoodsSellRecord> findBymonth(Integer id, Date createTime,Date createTime1) {
        return dao.findBymonth(id,createTime,createTime1);
    }

    @Override
    public List<RunfastGoodsSellRecord> findBytime(Date parse, Date parse1, Integer id, int page, int rows, Integer agentid) {

        return dao.findBytime(parse,parse1,id,page,rows,agentid);
    }

 /*   @Override
    public RunfastGoodsSellRecord getInfo(Integer id) {
        //新版本改成一个类了
        List<RunfastGoodsSellRecord> gr = dao.findById(id);//骑手id查找外卖订单信息
       *//* if(gr!=null){
            List<RunfastGoodsSellChildren> sublist = goodsSellRecordChildrenDao.findbyorderid(gr.getId());

            if(gr.getShowps()==null){
                gr.setShowps(new BigDecimal(0));

            }
            if(sublist!=null&&sublist.size()>0){
                for(RunfastGoodsSellChildren gs:sublist){
                   if(gs!=null){
                        GoodsSellStandard gss=null;
                        GoodsSellSubOption gso=null;
                        String showoption="";
                        if(gs.getGoodsSellStandardId()!=null){
                            gss=goodsSellStandardDao.get(gs.getGoodsSellStandardId());
                        }
                        if(gss!=null){
                            gs.setGoodsSellName(gs.getGoodsSellName());
                        }
                        if(!ComUtil.isEmpty(gs.getOptionIds())){
                            String[] strIds = gs.getOptionIds().split(",");
                            for(String strId:strIds){
                                int rid = ComUtil.getInt(strId);
                                gso=goodsSellSubOptionDao.get(rid);
                                if(gso!=null){
                                    showoption+=gso.getName()+";";
                                }

                            }
                            gs.setShowoption(showoption);

                        }

                    }
                }
            }
            gr.setGoodsSellRecordChildren(sublist);*//*
      *//*  }*//*
        for (int i = 0; i <gr.size() ; i++) {
            System.out.print(i);
        }
        return gr[1];
    }*/

    @Override
    public List<RunfastGoodsSellRecord> findListPageBean(Integer pageSize, Integer page, Integer status, Integer shopperId, Integer agentid, Integer teamid) {
        return dao.findListPageBean(pageSize,page,status,shopperId,agentid,teamid);
    }

    @Override
    public Integer findCount(Integer pageSize, Integer page, Integer status, Integer shopperId, Integer agentid, Integer teamid) {
        return dao.findCount(pageSize,page,status,shopperId,agentid,teamid);
    }

    @Override
    public List<Map<String,String>>  findByAgentnameAndbusinessnameAndTime(Integer agentid, String name, Date date1, Date date2,Integer isdelive) {
        return dao.findByAgentnameAndbusinessnameAndTime(agentid, name, date1, date2,isdelive);
    }

    @Override
    public List<Map<String,String>> findAgentnameMoney(Date createtime1, Date createatime2, Integer isdeliver) {
        return dao.findAgentnameMoney(createtime1, createatime2,isdeliver);
    }

    @Override
    public List<Map<String, BigDecimal>> findshopperAndCityAndtime(String cityname, String shoppername, Date ceateatime1, Date ceateatime2,Integer page,Integer pagesize) {
        return dao.findshopperAndCityAndtime(cityname, shoppername, ceateatime1, ceateatime2,page,pagesize);
    }

    @Override
    public int findByShopperIdOrderCodeCount(Integer shopperid) {
        return dao.findByShopperIdOrderCodeCount(shopperid);
    }

    @Override
    public int findCountShopperOrder(Integer shopperid) {
        return dao.findCountShopperOrder(shopperid);
    }

    @Override
    public int findCountStatus9(Integer shopperid) {
        return dao.findCountStatus9(shopperid);
    }

    @Override
    public List<RunfastGoodsSellRecord> findaftertime(Date date1, Date date2, String cityname, String shoppername) {
        return dao.findaftertime(date1, date2, cityname, shoppername);
    }

    @Override
    public List<RunfastGoodsSellRecord> finderrorOver(Date date1, Date date2, String cityname, String shoppername) {
        return dao.finderrorOver(date1, date2, cityname, shoppername);
    }

    @Override
    public List<RunfastGoodsSellRecord> findlastscore(Date date1, Date date2, String cityname, String shoppername) {
        return dao.findlastscore(date1, date2, cityname, shoppername);
    }

    @Override
    public List<RunfastGoodsSellRecord> findToday(Integer id, Date date1, Date date2) {
        return dao.findToday(id,date1,date2);
    }

    @Override
    public List<RunfastGoodsSellRecord> findstatus(Integer status,Integer page,Integer pagesize,Integer agentid,Integer shopperId,Date date) {
        return dao.findstatus(status,page,pagesize,agentid,shopperId,date);
    }

    @Override
    public Integer findstatuscount(Integer status,Integer page,Integer pagesize,Integer agentid,Integer shopperid,Date date) {
        return dao.findstatuscount(status,page,pagesize,agentid,shopperid,date);
    }

    @Override
    public Integer findstatuscount1(Integer status, Integer agentid) {
        return dao.findstatuscount1(status, agentid);
    }

    @Override
    public List<RunfastGoodsSellRecord> findBookTime(Integer shopperid,Date bookTime,Integer agentid) {
        return dao.findBookTime(shopperid,bookTime,agentid);
    }

    @Override
    public RunfastGoodsSellRecord findByOrderCodeid(Integer orderid) {
        return dao.findByOrderCodeid(orderid);
    }



    @Override
    public List<RunfastGoodsSellRecord> findAllAndTime(Integer id,Integer page, Integer pagesize, Date time1, Date time2) {
        return dao.findAllAndTime(id,page,pagesize,time1, time2);
    }

    @Override
    public Integer findAllAndTimecount(Integer id,Integer page, Integer pagesize, Date time1, Date time2) {
        return dao.findAllAndTimecount(id,page,pagesize,time1, time2);
    }

    @Override
    public Integer findNameAndCount(Integer shopperid, Integer page, Integer pagesize, Date time1, Date time2,String businessName) {
        return dao.findNameAndCount(shopperid, page, pagesize,time1,time2,businessName);
    }

    @Override
    public List<RunfastGoodsSellRecord> findstatusnewmsg( Integer page, Integer pageSize, Integer agentid) {
        return dao.findstatusnewmsg( page, pageSize, agentid);
    }
    @Override
    public Integer findstatusnewmsgcount( Integer page, Integer pageSize, Integer agentid) {
        return dao.findstatusnewmsgcount( page, pageSize, agentid);
    }

    @Override
    public List<Map<String,String>> findcommisson(Integer shopperid,Date date1,Date date2) {
        return dao.findcommisson(shopperid,date1,date2);
    }

    @Override
    public Integer findcommissoncount(Integer shopperid, Date time1, Date time2) {
        return dao.findcommissoncount(shopperid, time1, time2);
    }

    @Override
    public List<Map<String, String>> findcommisson7(Integer shopperid) {
        return dao.findcommisson7( shopperid);
    }

    @Override
    public List<Map<String, String>> findcommisson8(Integer shopperid) {
        return dao.findcommisson8( shopperid);
    }

    @Override
    public RunfastGoodsSellRecord get1(Integer id) {
        return dao.get1(id);
    }

    @Override
    public List<RunfastGoodsSellRecord> findByShopperIdAndStrutsSize(Integer shopperid) {
        return dao.findByShopperIdAndStrutsSize(shopperid);
    }

    @Override
    public Integer findShopperAndStatusErroCount(Integer shopperid) {
        return dao.findShopperAndStatusErroCount(shopperid);
    }


}